<template>
  <div class="station-echart">
    <div class="station-echart-modal">
      <div class="modal_border border_left">
        <div>
          <span data-v-jzl20210826="" style="opacity: 0" class="headerRadio hingelisHeard2"></span>

          <div v-if="experienceData.length > stationLength">
            <span v-for="(num, index) in leftRows" :key="index" class="hingelisHeard">
              <StationDetail1 :color="color"></StationDetail1>
            </span>
          </div>
          <span data-v-jzl20210826="" v-if="leftShow" style="margin-top: 98.5px; opacity: 0" class="hingeorgerHeard"></span>
        </div>
      </div>
      <div class="modal_content">
        <div style="display: flex" v-for="(item, index) in experienceData" :key="index">
          <div style="display: flex; width: 100%" :style="(index + 1) % 2 == 0 ? 'justify-content: end;' : ''">
            <div
              class="timeline"
              v-for="(v, i) in DisplayProcessing(experienceData, index + 1)"
              :key="i"
              :class="
                (i + 1) % stationLength != 0 && i != DisplayProcessing(experienceData, index + 1).length - 1 ? '' : 'node-width'
              "
            >
              <div class="Nodes Nodes_left">
                <StationDetail2 :color="color"></StationDetail2>
              </div>
              <div class="timeNodes t1" :class="i % 2 === 0 ? 'up' : 'down'">
                <div class="nodeTimes">
                  <span>{{ v.name }} </span>
                </div>
              </div>
              <div
                class="border"
                v-if="(i + 1) % stationLength != 0 && i != DisplayProcessing(experienceData, index + 1).length - 1"
              >
                <div class="borderTime" :style="{ background: color }">
                  <div class="borderTime-arrow" :class="(index + 1) % 2 != 0 ? '' : 'left'"></div>
                </div>
              </div>
            </div>
          </div>
        </div>
      </div>
      <div class="modal_border border_right">
        <div>
          <!-- 第一行 -->
          <span class="hingelis" v-if="experienceData.length > stationLength">
            <StationDetail1 :color="color"></StationDetail1>
          </span>
          <div v-if="experienceData.length > stationLength * 2">
            <span class="hingelis hingelis2" v-for="(num, index) in rightRows" :key="index">
              <StationDetail1 :color="color"></StationDetail1>
            </span>
          </div>
        </div>
      </div>
    </div>
  </div>
</template>
<script setup lang="ts" name="StationDetail">
import { ref, onMounted, watch } from "vue";
// import STATIONSvg from "../icon/STATIONSvg.vue";
import StationDetail1 from "../icon/station_detail_border.vue";
import StationDetail2 from "../icon/station_detail_node.vue";
import { Route } from "@/api/interface/sysManagement";

const props = defineProps({
  data: {
    type: Array as () => Route.ResStationList[],
    default: () => [] as Route.ResStationList[]
  },
  stationLength: {
    type: Number,
    default: 6
  },
  color: {
    type: String,
    default: "#00B5A9"
  }
});

const experienceData = ref<Route.ResStationList[]>([]);
let leftRows = ref(0);
let rightRows = ref(0);
let leftShow = ref(false);
let rightShow = ref(false);

const handlerData = () => {
  // 时间线数据
  experienceData.value = props.data || [];
  const rows = Math.ceil(experienceData.value.length / props.stationLength);
  const num = parseInt((rows / 2).toString());
  leftRows.value = rows === 2 ? 0 : rows % 2 === 0 ? num - 1 : num;
  rightRows.value = rows === 4 ? 1 : rows % 2 === 0 ? (num % 2 === 0 ? (num >= 4 ? num - 1 : num) : num - 1) : num - 1;
  leftShow.value = rows % 2 === 0;
  rightShow.value = rows === 1 ? false : rows % 2 === 1;
};

const DisplayProcessing = (Arg, Num) => {
  // 数据循环处理
  let arr = Arg.slice(props.stationLength * (Num - 1), props.stationLength * Num);
  arr = Num % 2 === 0 ? arr.reverse() : arr;
  return arr;
};

watch(
  () => props.data,
  () => {
    handlerData();
  },
  { deep: true, immediate: true }
);

onMounted(() => {
  handlerData();
});

// const onClickDate = data => {
//   console.log(data);
// };
</script>
<style scoped lang="scss">
$border-height: 136px;
$border-width: 64px;
$border-margin-top1: 52px;
$border-margin-top2: 104px;
$bordertime-height: 16px;
$node-width: 30px;
.node-width {
  width: 10px !important;
  min-width: 10px;
}
.station-echart {
  min-height: 220px;
  max-height: 480px;
  padding: 16px;
  overflow-y: auto;
  background: #f2f9ff;
}
.station-echart-modal {
  position: relative;
  display: flex;
  width: 100%;

  // margin-top: 20px
  .modal_border {
    width: $border-width;
  }
  .border_left {
    margin-left: 30px;
  }
  .border_right {
    margin-right: 30px;
  }
  .modal_content {
    flex: 1;
  }
}
.timeline {
  position: relative;
  display: flex;
  align-items: center;
  width: 100%;
  max-width: 120px;
  height: 120px;
}
.timeline2 {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: flex-end;
  width: 100%;
  height: 120px;
}
.border {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 100%;
  .borderTime {
    // background: #00B5A9;
    display: flex;
    align-items: center;
    justify-content: center;

    // border-bottom: 6px solid #00B5A9;
    width: 100%;
    height: $bordertime-height;
    &-arrow {
      width: 10px;
      height: 10px;
      background-image: url("../img/station_arrow.png");
      background-repeat: round;
    }
    .left {
      transform: rotateY(180deg);

      // margin-right: 35px;
    }
  }
  .b2 {
    margin-right: 5px;
  }
}
.Nodes {
  // background-image: url('../img/station_detail_node.png');
  // background-repeat: round;
  position: absolute;
  width: $node-width;
  min-width: $node-width;
  height: $node-width;
  margin: 0 -3px;
}
.Nodes_right {
  right: -5px;
}
.Nodes_left {
  left: -8px;
}
.timeNodes {
  position: absolute;
  width: 110px;
  text-align: center;
}
.t1 {
  left: -45px;
}
.t2 {
  right: -45px;
}
.up {
  bottom: 60%;
}
.down {
  top: 60%;
}
.nodeTimes {
  overflow: hidden;
  white-space: nowrap;

  // text-overflow: ellipsis;
  cursor: pointer;
}
.nodeTimelis {
  max-width: 150px;
  overflow: hidden;
  text-overflow: ellipsis;
  word-break: keep-all;
  white-space: nowrap;
  cursor: pointer;
}
.nodeTimelis:active {
  color: #1e9bff;
}
.btns-img {
  width: 16px;
  height: 16px;
}
.hingelis {
  display: block;
  width: 100%;
  height: $border-height;
  margin-top: 52px;

  // border: 2px solid #00B5A9;
  // border-radius: 0 20px 20px 0px;
  // border-left: 0px;
  // background-image: url('../img/station_detail_border.png');
  // background-repeat: round;
  margin-left: -2px;
  content: "";
}
.hingelis2 {
  margin-top: $border-margin-top2;
}
.hingelisHeard2 {
  margin-top: $border-margin-top1 + $bordertime-height;
}
.hingelisHeard {
  display: block;
  width: 100%;
  height: $border-height;

  // border: 2px solid #00B5A9;
  // border-radius: 20px 0px 0px 20px;
  // border-right: 0px;
  margin-top: $border-margin-top2;
  content: "";

  // background-image: url('../img/station_detail_border.png');
  // background-repeat: round;
  transform: rotateY(180deg);
}
.hingeorger {
  position: relative;
  display: block;
  width: 100%;
  margin: 49.5px 0;
  border-bottom: 1px solid #cccccc;
}
.hingeorgerHeard {
  position: relative;
  display: block;
  width: 100%;
  border-bottom: 1px solid #cccccc;
}
.hingeorgerHeard[data-v-jzl20210826]::after {
  position: absolute;
  top: -4px;
  left: -2px;
  content: "";
  border-top: 5px solid transparent;
  border-right: 12px solid #cccccc;
  border-bottom: 5px solid transparent;
}
.hingeorger[data-v-jzl20210826]::after {
  position: absolute;
  top: -4px;
  right: -2px;
  content: "";
  border-top: 5px solid transparent;
  border-bottom: 5px solid transparent;
  border-left: 12px solid #cccccc;
}
.headerRadio {
  position: relative;
  display: block;
  width: 100%;
  border-bottom: 1px solid #cccccc;
}
.headerRadio[data-v-jzl20210826]::after {
  position: absolute;
  top: -4px;
  top: 50%;
  right: 35px;
  left: -2px;
  width: 1px;
  height: 1px;
  content: "";
  background: #cccccc;
  border: 5px solid #cccccc;
  border-radius: 50%;
  transform: translate(0, -50%);
}
::-webkit-scrollbar {
  width: 3px;
  height: 3px;
}
::-webkit-scrollbar-thumb {
  background-color: #99a9bf;
  border-radius: 5px;
  box-shadow: inset 0 0 5px rgb(0 0 0 / 20%);
}
::-webkit-scrollbar-track {
  background-color: #d3dce6;
  border-radius: 5px;
  box-shadow: inset 0 0 5px rgb(0 0 0 / 20%);
}
svg {
  width: 100%;
  height: 100%;
}
</style>
